<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0px;
        }
        
        .box {
            height: 100px;
            width: 100px;
            background-color: red;
            position: relative;
        }
        
        .box1 {
            height: 100px;
            width: 100px;
            background-color: green;
            position: relative;
        }
    </style>
</head>

<body>
    <button>点击移动red盒子200px</button><br/>
    <button>点击移动green盒子400px</button><br/>
    <button>点击返回red盒子200px</button><br/>
    <div class="box"></div>
    <div class="box1"></div>
</body>
<script src="./animation.js"></script>
<script>
    var bn = document.querySelectorAll("button");
    var box = document.querySelector(".box");
    var box1 = document.querySelector(".box1");
    bn[0].addEventListener('click', function() {
        animation(box, 200, function() {
            box.style.background = 'pink';
        });
    });
    bn[1].addEventListener('click', function() {
        animation(box1, 400, function() {
            box1.style.background = 'yellowgreen';
        });
    });
    bn[2].addEventListener('click', function() {
        animation(box, 0, function() {
            box.style.background = 'pink';
        });
    });
</script>

</html>